package cn.moukou.dictator.util;

import cn.moukou.dictator.pojo.Teacher;
import org.neo4j.ogm.typeconversion.CompositeAttributeConverter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TeacherConverter implements CompositeAttributeConverter<Teacher> {
    @Override
    public Map<String, ?> toGraphProperties(Teacher entity) {
        Map<String, Object> properties = new HashMap<>();
        if (entity != null)  {
            properties.put("teacher_name", entity.getName());
            properties.put("teacher_age", entity.getAge());
            properties.put("teacher_sex", entity.getSex());
            properties.put("title", entity.getTitle());
            properties.put("teacher_avatar", entity.getAvatar());
            properties.put("teacher_class_label", entity.getClassLabel());
            properties.put("teacher_award_list", entity.getAwardList());

        }
        return properties;
    }

    @Override
    public Teacher toEntityAttribute(Map<String, ?> map) {
        if(!map.get("node_type").toString().equals("teacher")) {
            return null;
        }
        Teacher entity = new Teacher();
        entity.setName((String) map.get("teacher_name"));
        entity.setAge((String) map.get("teacher_age"));
        entity.setSex((String) map.get("teacher_sex"));
        entity.setAvatar((String) map.get("teacher_avatar"));
        entity.setClassLabel((String) map.get("teacher_class_label"));
        entity.setAwardList((List<String>) map.get("teacher_award_list"));
        entity.setTitle((String) map.get("title"));

        return entity;
    }
}
